# Acting under Chapter 7: Data Processing #
# Author: Johannes Scherzinger #
# Date: 08.02.2021 #


# Packages
library(tidyverse)


# use this script to construct IVs and DV used in "Acting under Chapter 7".
# use in combination with UNSC_main.RData



#### Construct Independent Variables from Speeches - corresponding to selected keywords ####

#### Genocide ####

# raw count
UNSC$gen.count <- str_count(tolower(UNSC$text.x), "genocide")

# presence in Speech
UNSC$gen.pres <- grepl("genocide", tolower(UNSC$text.x))
sum(UNSC$gen.pres)/nrow(UNSC)

# total mentioning
UNSC$gen.total <- cumsum(UNSC$gen.count)

#### Humanitarian Crisis ####

# raw count
UNSC$crisis.count <- str_count(tolower(UNSC$text.x), "humanitarian crisis")

# presence in Speech
UNSC$crisis.pres <- grepl("humanitarian crisis", tolower(UNSC$text.x))
sum(UNSC$crisis.pres)/nrow(UNSC)


# total mentioning
UNSC$crisis.total <- cumsum(UNSC$crisis.count)

#### Responsibility to Protect (R2P) ####

# raw count
UNSC$r2p.count <- str_count(tolower(UNSC$text.x), "responsibility to protect")

# presence in Speech
UNSC$r2p.pres <- grepl("responsibility to protect", tolower(UNSC$text.x))
sum(UNSC$r2p.pres)/nrow(UNSC)

# total mentioning
UNSC$r2p.total <- cumsum(UNSC$r2p.count)

#### Human Rights ####

# raw count
UNSC$hr.count <- str_count(tolower(UNSC$text.x), "human right |human rights")

# presence in Speech
UNSC$hr.pres <- grepl("human right |human rights", tolower(UNSC$text.x))
sum(UNSC$hr.pres)/nrow(UNSC)

# total mentioning
UNSC$hr.total <- cumsum(UNSC$hr.count)

#### Regional Security ####

# raw count
UNSC$reg.count <- str_count(tolower(UNSC$text.x), "regional security")

# presence in speech
UNSC$reg.pres <- grepl("regional security", tolower(UNSC$text.x))
sum(UNSC$reg.pres)/nrow(UNSC)

# total mentioning
UNSC$reg.total <- cumsum(UNSC$reg.count)

#### Democracy ####

# raw count
UNSC$dem.count <- str_count(tolower(UNSC$text.x), "democracy")

# presence in speech
UNSC$dem.pres <- grepl("democracy", tolower(UNSC$text.x))
sum(UNSC$dem.pres)/nrow(UNSC)

# total mentioning
UNSC$dem.total <- cumsum(UNSC$dem.count)


#### Terrorism ####

# raw count
UNSC$terror.count <- str_count(tolower(UNSC$text.x), "terrorism |terror ")

# presence in speech
UNSC$terror.pres <- grepl("terrorism |terror ", tolower(UNSC$text.x))
sum(UNSC$terror.pres)/nrow(UNSC)

# total mentioning
UNSC$terror.total <- cumsum(UNSC$terror.count)


#### Other: Control variables ####

#### P5 ####

UNSC$P5 <- str_detect(tolower(UNSC$country), "(united states of america|russian federation|china|france|united kingdom of great britain and northern ireland)")


#### Dependent Variable #####

# The DV is created in this study by using two dictionaries
# The first one indicates whether the UNSC refers to Chapter 7 in its resolution
# The second establishes whether indeed "all necessary measures" are allowed to be used

#### Chapter VII #####

# raw count
UNSC$chapterVII.count <- str_count(tolower(UNSC$text.y), "chapter vii")
UNSC$chapterVII.pres <- grepl("chapter vii", tolower(UNSC$text.y))
sum(UNSC$chapterVII.pres)/nrow(UNSC)

# total mentioning
UNSC$chapterVII.total <- cumsum(UNSC$chapterVII.count)


##### Intervention Language ######


# raw count
UNSC$inter.count <- str_count(tolower(UNSC$text.y), "take all necessary measures|using all necesssary means|use all necessary means|with all necessary means")
UNSC$inter.pres <- grepl("take all necessary measures|using all necessary means|use all necessary means|with all necessary means", tolower(UNSC$text.y))
sum(UNSC$inter.pres)/nrow(UNSC)


# total mentioning
UNSC$inter.total <- cumsum(UNSC$inter.count)

# The combination of these two variables forms the Dependent Variable: Authorization of Force #


UNSC$auth <- UNSC$inter.pres & UNSC$chapterVII.pres
sum(UNSC$auth)/nrow(UNSC)



